package log;

public class LogItem
{
    public int index = 0;
    public long time = 0;
    public String dateTime = "";
    public String level = "";
    public String tag = "";
    public String content = "";
    public int pid = 0;
    public int tid = 0;
    public String module = "";
    public String file = "";
    public int lineNumber = 0;


    public enum Field
    {
        Index("Index"),
        Time("Time"),
        Level("Level"),
        Tag("Tag"),
        Message("Message"),
        Pid("Pid"),
        Tid("Tid"),
        Module("Module"),
        File("File"),
        Line("Line");

        private String name;

        Field(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    public static int getFieldCount() {
        return Field.values().length;
    }

    public static String getFieldName(int index) {
        Field[] values = Field.values();
        if (index >= values.length) {
            return "unknown";
        }
        else {
            return values[index].toString();
        }
    }

    public String getFieldByIndex(int fieldIndex)
    {
        Field[] values = Field.values();
        if (fieldIndex >= values.length) {
            return "";
        }
        Field field = values[fieldIndex];

        switch (field) {
            case Index:
                return Integer.toString(index);
            case Time:
                return dateTime;
            case Level:
                return level;
            case Tag:
                return tag;
            case Message:
                return content;
            case Pid:
                return Integer.toString(pid);
            case Tid:
                return Integer.toString(tid);
            case Module:
                return module;
            case File:
                return file;
            case Line:
                return Integer.toString(lineNumber);

        }
        return "";
    }

    @Override
    public String toString() {
        return String.format("%d %s(%d) %s [%d|%d] <%s> %s", index, dateTime, time, level, pid, tid, tag, content);
    }
}
